package org.pb;

import java.util.ArrayList;
import java.util.List;

import org.springframework.http.MediaType;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.widget.Toast;

public  class TaxiApplication extends Application {

	private static RestTemplate restTemplate = setRestTemplate();

	private static Context context;
	// dla emulatora
	public static final String BASE_URL = "http://10.0.2.2:9090";
	
	//dla telefonu
	//public static final String BASE_URL = "http://192.168.1.52:9090";
	public static final String PREFIX="/pracamgr";
	public static final String LOG_URL = PREFIX+"/loginPerson.json";
	public static final String REGISTER_URL = PREFIX+"/registerPerson.json";
	public static final String GETACTIVEALERTS_URL = PREFIX+"/getActiveAlert/idOrder/";
	public static final String GETALLALERTS_URL = PREFIX+"/getAllAlerts/userId/";
	public static final String GETACTIVEORDERS_URL = PREFIX+"/getActiveOrders/idPerson/";
	public static final String GETALLORDERS_URL = PREFIX+"/getAllOrders/idPerson/";
	public static final String SETORDER_URL = PREFIX+"/setOrder.json";
	
	public static final String PREFS_NAME = "TaxiPrefsFile";






	
	private static String userId;
	public void onCreate() {
		super.onCreate();
		TaxiApplication.context = getApplicationContext();
	}

	
	public static Context getAppContext() {
		return TaxiApplication.context;
	}



	public static RestTemplate setRestTemplate() {
		RestTemplate restTemplate = new RestTemplate();
		List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
		messageConverters.add(new FormHttpMessageConverter());
		messageConverters.add(new StringHttpMessageConverter());
		List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
		MediaType mediaType = new MediaType("application", "json");
		//MediaType mediaType = new MediaType("text", "plain");

		supportedMediaTypes.add(mediaType);
		MappingJacksonHttpMessageConverter jacksonConverter = new MappingJacksonHttpMessageConverter();
		jacksonConverter.setSupportedMediaTypes(supportedMediaTypes);
		messageConverters.add(jacksonConverter);
		restTemplate.setMessageConverters(messageConverters);
		HttpComponentsClientHttpRequestFactory httpFactory=new HttpComponentsClientHttpRequestFactory();
		httpFactory.setReadTimeout(3000);
		//restTemplate
		//		.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
		restTemplate.setRequestFactory(httpFactory);
		return restTemplate;
	}

	public static RestTemplate getRestTemplate() {

		return restTemplate;
	}


}
